package com.dfbz.netctoss.service.impl;

import com.dfbz.netctoss.entity.AdminInfo;
import com.dfbz.netctoss.entity.Privilege;
import com.dfbz.netctoss.mapper.AdminInfoMapper;
import com.dfbz.netctoss.service.AdminInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AdminInfoServiceImpl implements AdminInfoService {

    @Autowired
    AdminInfoMapper mapper;

    @Override
    public PageInfo<AdminInfo> selectPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<AdminInfo> adminInfos = mapper.selectAllAdmin();
        return new PageInfo<>(adminInfos);
    }

    @Override
    public AdminInfo findByAdmincode(String admincode) {
        return mapper.findByAdmincode(admincode);
    }

    @Override
    public AdminInfo findRolesByAdminCode(String adminCode) {
        return mapper.findRolesByAdminCode(adminCode);
    }

    @Override
    public List<Privilege> selectAllPrivilegeByRId(Integer roleId) {
        return mapper.selectAllPrivilegeByRId(roleId);
    }

    @Override
    public int updateDetail(AdminInfo adminInfo) {
        return mapper.updateByPrimaryKeySelective(adminInfo);
    }
}
